package config_manager

import (
	"github.com/golang/protobuf/proto"
	"go_server/game_server/dataconfig/configpb"
	"go_server/game_server/util"
	"go_server/zinx/zlog"
	"path/filepath"
)

var (
	configFilePath                string
	tableBuildSheetBuild          map[int32]*configpb.StcTableBuild_SheetBuild_3ADA1586
	tableBuildSheetLevel          map[int32]map[int32]*configpb.StcTableBuild_SheetLevel_295B238C
	tableButtonSheetButton        map[int32]*configpb.StcTableButton_SheetButton_513D7B2C
	tableMap3DConfigSheetBlock    map[int32]*configpb.StcTable_Map3DConfig_Sheet_Block_A734F594
	tableMap3DConfigSheetBuild    map[int32]*configpb.StcTable_Map3DConfig_Sheet_Build_7E655245
	tableMap3DConfigSheetMap      map[int32]*configpb.StcTable_Map3DConfig_Sheet_Map_252E6EDF
	tableMap3DConfigSheetWall     map[int32]*configpb.StcTable_Map3DConfig_Sheet_Wall_9A8E0E29
	tableMap3DConfigSheetSundries map[int32]*configpb.StcTable_Map3DConfig_Sheet_Sundries_838387F6
	tableRobotSheetRobot          map[int32]*configpb.StcTableRobot_SheetRobot_E97F9FC6
	tableGameSettingSheetGame     configpb.StcTable_GameSetting_Sheet_Game_A7D9BDC0
	tableItemSheetItem            map[int32]*configpb.StcTableItem_SheetItem_6508A6FE
	tableUnlockSheetUnlock        map[int32]*configpb.StcTableUnlock_SheetUnlock_DE232354

	tableHeroSheetHero  map[int32]*configpb.StcTableHero_SheetHero_220164B4
	tableHeroSheetLevel map[int32]*configpb.StcTableHero_SheetLevel_1BF89EB8
	tableHeroSheetStar  map[int32]*configpb.StcTableHero_SheetStar_9F49B1D8
	tableHeroSheetCell  map[int32]*configpb.StcTableHeroCell_SheetCell_166605B4

	tableLevelChapterSheetLevelChapter     map[int32]*configpb.StcTableLevelChapter_SheetLevelChapter_C81D4AC6
	tableTaskSheetTask                     map[int32]*configpb.StcTableTask_SheetTask_27074BFE
	tableActivityConfigSheetActivityConfig map[int32]*configpb.StcTable_ActivityConfig_Sheet_ActivityConfig_805A3166
	tableHeroDrawSheetDraw                 map[int32]*configpb.StcTableHeroDraw_SheetDraw_F6601B8C
	tableHeroDrawSheetDrawItem             map[int32]*configpb.StcTableHeroDraw_SheetDrawItem_7602FC84
	tableShopSheetShop                     map[int32]*configpb.StcTableShop_SheetShop_29EA6FE4
)

func init() {
	configFileViper, _ := util.CreateConfig("data")
	configFileViper.WatchConfig()
	configFilePath, _ = filepath.Abs(configFileViper.GetString("config_path"))
	configFilePath += "/"
}

func LoadAllGameData() {
	zlog.Debug("LoadAllGameData Begin")
	load_Table_build_Sheet_build_Data("StcTable_build_Sheet_build.bytes")
	load_Table_build_Sheet_level_Data("StcTable_build_Sheet_level.bytes")
	load_Table_button_Sheet_button_Data("StcTable_button_Sheet_button.bytes")
	load_Table_Map3DConfig_Sheet_Block_Data("StcTable_Map3DConfig_Sheet_Block.bytes")
	load_Table_Map3DConfig_Sheet_Build_Data("StcTable_Map3DConfig_Sheet_Build.bytes")
	load_Table_Map3DConfig_Sheet_Map_Data("StcTable_Map3DConfig_Sheet_Map.bytes")
	load_Table_Map3DConfig_Sheet_Wall_Data("StcTable_Map3DConfig_Sheet_Wall.bytes")
	load_Table_Map3DConfig_Sheet_Sundries_Data("StcTable_Map3DConfig_Sheet_Sundries.bytes")
	load_Table_Robot_SheetRobot_Data("StcTable_robot_Sheet_robot.bytes")
	load_Table_GameSetting_Sheet_Game_Data("StcTable_GameSetting_Sheet_Game.bytes")
	load_Table_Item_Sheet_Item_Data("StcTable_item_Sheet_item.bytes")
	load_Table_Unlock_Sheet_Unlock_Data("StcTable_unlock_Sheet_unlock.bytes")
	load_StcTableHero_SheetHero("StcTable_hero_Sheet_hero.bytes")
	load_StcTableHero_SheetLevel("StcTable_hero_Sheet_level.bytes")
	load_StcTableHero_SheetStar("StcTable_hero_Sheet_star.bytes")
	load_StcTableHeroCell_SheetCell("StcTable_heroCell_Sheet_cell.bytes")
	load_StcTableLevelChapter_SheetLevelChapter("StcTable_levelChapter_Sheet_levelChapter.bytes")
	load_StcTableCurrency_SheetCurrency("StcTable_currency_Sheet_currency.bytes")
	load_StcTableTask_SheetTask("StcTable_task_Sheet_task.bytes")
	load_StcTableActivityConfig_SheetActivityConfig("StcTable_ActivityConfig_Sheet_ActivityConfig.bytes")
	load_StcTableHeroDraw_SheetDraw("StcTable_heroDraw_Sheet_draw.bytes")
	load_StcTableHeroDraw_SheetDrawItem("StcTable_heroDraw_Sheet_draw_item.bytes")
	load_StcTableProperty_SheetProperty("StcTable_property_Sheet_property.bytes")
	load_StcTableShop_SheetShop("StcTable_shop_Sheet_shop.bytes")
	zlog.Debug("LoadAllGameData End\n")

	Init()
}

func load_Table_Map3DConfig_Sheet_Sundries_Data(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_Map3DConfig_Sheet_Wall_Sundries_Data start!!!")
	msg := &configpb.DataSet_StcTable_Map3DConfig_Sheet_Sundries_838387F6{}
	proto.Unmarshal(content, msg)

	tableMap3DConfigSheetSundries = make(map[int32]*configpb.StcTable_Map3DConfig_Sheet_Sundries_838387F6)

	for _, info := range msg.Items {
		tableMap3DConfigSheetSundries[info.Id] = info
	}
	zlog.Debug("load_Table_Map3DConfig_Sheet_Wall_Sundries_Data complete!!!")
}

func load_Table_Map3DConfig_Sheet_Wall_Data(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_Map3DConfig_Sheet_Wall_Data start!!!")
	msg := &configpb.DataSet_StcTable_Map3DConfig_Sheet_Wall_9A8E0E29{}
	proto.Unmarshal(content, msg)

	tableMap3DConfigSheetWall = make(map[int32]*configpb.StcTable_Map3DConfig_Sheet_Wall_9A8E0E29)

	for _, info := range msg.Items {
		tableMap3DConfigSheetWall[info.Id] = info
	}
	zlog.Debug("load_Table_Map3DConfig_Sheet_Wall_Data complete!!!")
}

func load_Table_Map3DConfig_Sheet_Map_Data(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_Map3DConfig_Sheet_Map_Data start!!!")
	msg := &configpb.DataSet_StcTable_Map3DConfig_Sheet_Map_252E6EDF{}
	proto.Unmarshal(content, msg)

	tableMap3DConfigSheetMap = make(map[int32]*configpb.StcTable_Map3DConfig_Sheet_Map_252E6EDF)

	for _, info := range msg.Items {
		tableMap3DConfigSheetMap[info.Id] = info
	}
	zlog.Debug("load_Table_Map3DConfig_Sheet_Map_Data complete!!!")
}

func load_Table_Map3DConfig_Sheet_Build_Data(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_Map3DConfig_Sheet_Build_Data start!!!")
	msg := &configpb.DataSet_StcTable_Map3DConfig_Sheet_Build_7E655245{}
	proto.Unmarshal(content, msg)

	tableMap3DConfigSheetBuild = make(map[int32]*configpb.StcTable_Map3DConfig_Sheet_Build_7E655245)

	for _, info := range msg.Items {
		tableMap3DConfigSheetBuild[info.Id] = info
	}
	zlog.Debug("load_Table_Map3DConfig_Sheet_Build_Data complete!!!")
}

func load_Table_Map3DConfig_Sheet_Block_Data(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_Map3DConfig_Sheet_Block_Data start!!!")
	msg := &configpb.DataSet_StcTable_Map3DConfig_Sheet_Block_A734F594{}
	proto.Unmarshal(content, msg)

	tableMap3DConfigSheetBlock = make(map[int32]*configpb.StcTable_Map3DConfig_Sheet_Block_A734F594)

	for _, info := range msg.Items {
		tableMap3DConfigSheetBlock[info.Id] = info
	}
	zlog.Debug("load_Table_Map3DConfig_Sheet_Block_Data complete!!!")
}

func load_Table_button_Sheet_button_Data(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_button_Sheet_button_Data start!!!")
	msg := &configpb.DataSet_StcTableButton_SheetButton_513D7B2C{}
	proto.Unmarshal(content, msg)

	tableButtonSheetButton = make(map[int32]*configpb.StcTableButton_SheetButton_513D7B2C)

	for _, info := range msg.Items {
		tableButtonSheetButton[info.Id] = info
	}
	zlog.Debug("load_Table_button_Sheet_button_Data complete!!!")
}

func load_Table_build_Sheet_level_Data(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_build_Sheet_level_Data start!!!")
	msg := &configpb.DataSet_StcTableBuild_SheetLevel_295B238C{}
	proto.Unmarshal(content, msg)

	tableBuildSheetLevel = make(map[int32]map[int32]*configpb.StcTableBuild_SheetLevel_295B238C)

	for _, info := range msg.Items {
		if tableBuildSheetLevel[info.Id] == nil {
			tableBuildSheetLevel[info.Id] = make(map[int32]*configpb.StcTableBuild_SheetLevel_295B238C)
		}
		tableBuildSheetLevel[info.Id][info.Level] = info
	}
	zlog.Debug("load_Table_build_Sheet_level_Data complete!!!")
}

func load_Table_build_Sheet_build_Data(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_build_Sheet_build_Data start!!!")
	msg := &configpb.DataSet_StcTableBuild_SheetBuild_3ADA1586{}
	proto.Unmarshal(content, msg)

	tableBuildSheetBuild = make(map[int32]*configpb.StcTableBuild_SheetBuild_3ADA1586)
	for _, info := range msg.Items {
		tableBuildSheetBuild[info.Id] = info
	}
	zlog.Debug("load_Table_build_Sheet_build_Data complete!!!")
}

func load_Table_Robot_SheetRobot_Data(fileName string) {

	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_Robot_SheetRobot_Data start!!!")
	msg := &configpb.DataSet_StcTableRobot_SheetRobot_E97F9FC6{}
	proto.Unmarshal(content, msg)

	tableRobotSheetRobot = make(map[int32]*configpb.StcTableRobot_SheetRobot_E97F9FC6)

	for _, info := range msg.Items {
		tableRobotSheetRobot[info.Id] = info
	}
	zlog.Debug("load_Table_Robot_SheetRobot_Data complete!!!")
}

func load_Table_GameSetting_Sheet_Game_Data(fileName string) {
	//tableGameSettingSheetGame = make(map[int32]*configpb.StcTable_GameSetting_Sheet_Game_A7D9BDC0)
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)
	zlog.Debug("load_Table_Robot_SheetRobot_Data start!!!")
	msg := &configpb.DataSet_StcTable_GameSetting_Sheet_Game_A7D9BDC0{}
	proto.Unmarshal(content, msg)
	tableGameSettingSheetGame = *msg.Item
	zlog.Debug("load_Table_Robot_SheetRobot_Data complete!!!")
}

func load_Table_Item_Sheet_Item_Data(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_Item_Sheet_Item_Data start!!!")
	msg := &configpb.DataSet_StcTableItem_SheetItem_6508A6FE{}
	proto.Unmarshal(content, msg)

	tableItemSheetItem = make(map[int32]*configpb.StcTableItem_SheetItem_6508A6FE)

	for _, info := range msg.Items {
		tableItemSheetItem[info.Id] = info
	}
	zlog.Debug("load_Table_Item_Sheet_Item_Data complete!!!")
}

func load_Table_Unlock_Sheet_Unlock_Data(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_Table_Unlock_Sheet_Unlock_Data start!!!!")
	msg := &configpb.DataSet_StcTableUnlock_SheetUnlock_DE232354{}
	proto.Unmarshal(content, msg)

	tableUnlockSheetUnlock = make(map[int32]*configpb.StcTableUnlock_SheetUnlock_DE232354)

	for _, info := range msg.Items {
		tableUnlockSheetUnlock[info.Id] = info
	}

	zlog.Debug("load_Table_Unlock_Sheet_Unlock_Data complete!!!!")
}

func load_StcTableHero_SheetHero(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_StcTableHero_SheetHero start!!!")
	msg := &configpb.DataSet_StcTableHero_SheetHero_220164B4{}
	proto.Unmarshal(content, msg)

	tableHeroSheetHero = make(map[int32]*configpb.StcTableHero_SheetHero_220164B4)

	for _, info := range msg.Items {
		tableHeroSheetHero[info.Id] = info
	}
	zlog.Debug("load_StcTableHero_SheetHero complete!!!")
}

func load_StcTableHero_SheetLevel(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_StcTableHero_SheetLevel start!!!")
	msg := &configpb.DataSet_StcTableHero_SheetLevel_1BF89EB8{}
	proto.Unmarshal(content, msg)

	tableHeroSheetLevel = make(map[int32]*configpb.StcTableHero_SheetLevel_1BF89EB8)

	for _, info := range msg.Items {
		tableHeroSheetLevel[info.Id] = info
	}
	zlog.Debug("StcTableHero_SheetLevel complete!!!")
}

func load_StcTableHero_SheetStar(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_StcTableHero_SheetStar start!!!")
	msg := &configpb.DataSet_StcTableHero_SheetStar_9F49B1D8{}
	proto.Unmarshal(content, msg)

	tableHeroSheetStar = make(map[int32]*configpb.StcTableHero_SheetStar_9F49B1D8)

	for _, info := range msg.Items {
		tableHeroSheetStar[info.Id] = info
	}
	zlog.Debug("StcTableHero_SheetStar complete!!!")
}

func load_StcTableHeroCell_SheetCell(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_StcTableHeroCell_SheetCell start!!!")
	msg := &configpb.DataSet_StcTableHeroCell_SheetCell_166605B4{}
	proto.Unmarshal(content, msg)

	tableHeroSheetCell = make(map[int32]*configpb.StcTableHeroCell_SheetCell_166605B4)

	for _, info := range msg.Items {
		tableHeroSheetCell[info.Id] = info
	}
	zlog.Debug("StcTableHeroCell_SheetCell complete!!!")
}

func load_StcTableLevelChapter_SheetLevelChapter(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_StcTableLevelChapter_SheetLevelChapter start!!!")
	msg := &configpb.DataSet_StcTableLevelChapter_SheetLevelChapter_C81D4AC6{}
	proto.Unmarshal(content, msg)

	tableLevelChapterSheetLevelChapter = make(map[int32]*configpb.StcTableLevelChapter_SheetLevelChapter_C81D4AC6)

	for _, info := range msg.Items {
		tableLevelChapterSheetLevelChapter[info.Id] = info
	}
	zlog.Debug("load_StcTableLevelChapter_SheetLevelChapter complete!!!")
}

func load_StcTableTask_SheetTask(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_StcTableTask_SheetTask start!!!")
	msg := &configpb.DataSet_StcTableTask_SheetTask_27074BFE{}
	proto.Unmarshal(content, msg)

	tableTaskSheetTask = make(map[int32]*configpb.StcTableTask_SheetTask_27074BFE)

	for _, info := range msg.Items {
		tableTaskSheetTask[info.Id] = info
	}
	zlog.Debug("load_StcTableTask_SheetTask complete!!!")
}

func load_StcTableActivityConfig_SheetActivityConfig(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_StcTableActivityConfig_SheetActivityConfig start!!!")
	msg := &configpb.DataSet_StcTable_ActivityConfig_Sheet_ActivityConfig_805A3166{}
	proto.Unmarshal(content, msg)

	tableActivityConfigSheetActivityConfig = make(map[int32]*configpb.StcTable_ActivityConfig_Sheet_ActivityConfig_805A3166)

	for _, info := range msg.Items {
		tableActivityConfigSheetActivityConfig[info.Id] = info
	}
	zlog.Debug("load_StcTableActivityConfig_SheetActivityConfig complete!!!")
}

func load_StcTableHeroDraw_SheetDraw(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_StcTableHeroDraw_SheetDraw start!!!")
	msg := &configpb.DataSet_StcTableHeroDraw_SheetDraw_F6601B8C{}
	proto.Unmarshal(content, msg)

	tableHeroDrawSheetDraw = make(map[int32]*configpb.StcTableHeroDraw_SheetDraw_F6601B8C)

	for _, info := range msg.Items {
		tableHeroDrawSheetDraw[info.Id] = info
	}
	zlog.Debug("load_StcTableHeroDraw_SheetDraw complete!!!")
}

func load_StcTableHeroDraw_SheetDrawItem(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_StcTableHeroDraw_SheetDrawItem start!!!")
	msg := &configpb.DataSet_StcTableHeroDraw_SheetDrawItem_7602FC84{}
	proto.Unmarshal(content, msg)

	tableHeroDrawSheetDrawItem = make(map[int32]*configpb.StcTableHeroDraw_SheetDrawItem_7602FC84)

	for _, info := range msg.Items {
		tableHeroDrawSheetDrawItem[info.Id] = info
	}
	zlog.Debug("load_StcTableHeroDraw_SheetDrawItem complete!!!")
}

func load_StcTableShop_SheetShop(fileName string) {
	fullPath := configFilePath + fileName
	content := util.GetReadFileBuf(fullPath)

	zlog.Debug("load_StcTableShop_SheetShop start!!!")
	msg := &configpb.DataSet_StcTableShop_SheetShop_29EA6FE4{}
	proto.Unmarshal(content, msg)

	tableShopSheetShop = make(map[int32]*configpb.StcTableShop_SheetShop_29EA6FE4)

	for _, info := range msg.Items {
		tableShopSheetShop[info.Id] = info
	}
	zlog.Debug("load_StcTableShop_SheetShop complete!!!")
}
